package com.ruoyi.system.media;

import com.ruoyi.system.domain.CpcEf02;

/**
 * CPC卡计费信息文件(DF01/EF04)的编码信息
 */
public class CpcEf04EdModel {
    public static final int MSG_LEN = 512;

    /**
     * 过省信息(1-506,506,bn)
     * 每条过省信息由23个字节组成,详见PassInfoED描述, 最多存储22条过省信息
     */
    public CpcProvEd[] provPass = new CpcProvEd[22];

    /**
     * 备用(507-512,6,bn)
     */
    public byte[] spareDFEF04 = new byte[6];

    //构造函数
    public CpcEf04EdModel() {
        for (int aa = 0; aa < provPass.length; aa++) {
            provPass[aa] = new CpcProvEd();
        }
        spareDFEF04 = ZTools.hex2bin(6, "FFFFFFFFFFFF");
    }

    /**
     * 信息编码
     *
     * @param dd
     * @return
     */
    public static CpcEf04EdModel encoded(CpcEf04Model dd) {
        CpcEf04EdModel ed = new CpcEf04EdModel();
        for (int aa = 0; aa < dd.provPass.length; aa++) {
            ed.provPass[aa] = CpcProvEd.encoded(dd.provPass[aa]);
        }

        return ed;
    }

    public byte[] toBytes() {
        byte[] temp = new byte[MSG_LEN];
        for (int aa = 0; aa < provPass.length; aa++) {
            System.arraycopy(provPass[aa].toBytes(), 0, temp, CpcProvEd.MSG_LEN * aa, CpcProvEd.MSG_LEN);
            System.arraycopy(spareDFEF04, 0, temp, CpcProvEd.MSG_LEN * provPass.length, spareDFEF04.length);
        }

        return temp;
    }

    public String toHexStr() {
        return ZTools.bin2hex(toBytes());
    }
}
